//
// JsonRpc++ Copyright (c) 2007 by Peter Wang
//
#ifndef _JSONRPCUTIL_H_
#define _JSONRPCUTIL_H_

#if defined(_MSC_VER)
# pragma warning(disable:4786)    // identifier was truncated in debug info
#endif

#ifndef MAKEDEPEND
# include <string>
#endif
#include <assert.h>

#if defined(_MSC_VER)
# define snprintf	    _snprintf
# define vsnprintf    _vsnprintf
# define strcasecmp	  _stricmp
# define strncasecmp	_strnicmp
#elif defined(__BORLANDC__)
# define strcasecmp stricmp
# define strncasecmp strnicmp
#endif

#include "json\\Json.h"
#include "define.h"

namespace JsonRpc {

  class JsonRpcUtil {
  private:
	  static FILE *jlogf;
	  static BOOL jfail;  
  public:

    //! Dump messages somewhere
    static void log(int level, const char* fmt, ...);
	static void log_str(int level, const char* buf, int len);

    //! Dump error messages somewhere
    static void error(const char* fmt, ...);

  };

#if (defined(_MSC_VER) && (_MSC_VER > 1200))
  namespace impl {
	template < class R > 
   inline R getValue(Json::Value & v)
	{
        assert(0);
        };

	template < > 
   inline int getValue(Json::Value & v)
	{
    return v.asInt();
        };

	template < > 
   inline unsigned int getValue(Json::Value & v)
	{
    return v.asUInt();
        }

	template < > 
   inline const char * getValue(Json::Value & v)
	{
    return v.asCString();
        }

	template < > 
   inline std::string getValue(Json::Value & v)
	{
    return v.asString();
        }

	template < > 
   inline double getValue(Json::Value & v)
	{
    return v.asDouble();
        }

	template < > 
   inline bool getValue(Json::Value & v)
	{
    return v.asBool();
        }

	template < > 
   inline Json::Value & getValue(Json::Value & v)
	{
    return v;
        }
        
	template < > 
   inline Json::Value  getValue(Json::Value & v)
	{
    return v;
        }
        
  } // namespace impl
#endif
} // namespace JsonRpc

#endif // _JSONRPCUTIL_H_
